package com.dlyk.web;

import com.dlyk.model.RolePermission;
import com.dlyk.result.R;
import com.dlyk.service.RolePermissionService;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

/**
 * 角色权限
 */
@RestController
public class RolePermissionController {

    @Resource
    private RolePermissionService rolePermissionService;

    /**
     * 角色授权
     */
    @PostMapping("/api/role/permission/add")
    public R addRolePermission(@RequestBody RolePermission rolePermission) {

        // 这里就不使用Query对象接收了，直接使用RolePermission对象接收

        int add = rolePermissionService.addRolePermission(rolePermission);

        return add >= 1 ? R.OK() : R.FAIL();
    }

    /**
     * 移除权限
     */
    @DeleteMapping("/api/role/permission/remove")
    public R removeRolePermission(Integer roleId, Integer permissionId) {

        int remove = rolePermissionService.removeRolePermissionByRoleIdAndPermissionId(roleId, permissionId);

        return remove >= 1 ? R.OK() : R.FAIL();
    }

}

